package org.example;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class TestMaven {
    public static void main(String[] args) throws Exception {
        System.out.println("这是第一个maven的项目");
        System.out.println("查询数据库，获取所有的用户信息：");
        //注册驱动
        Class.forName("com.mysql.jdbc.Driver");
        Connection conn =  DriverManager.getConnection("jdbc:mysql://localhost:3306/test_maven",
                "root", "");
        PreparedStatement pstmt =  conn.prepareStatement("select * from user ");
        ResultSet rs =  pstmt.executeQuery();
        while (rs.next()){
            System.out.print(rs.getInt("id") + "\t");
            System.out.print(rs.getString("username") + "\t");
            System.out.print(rs.getInt("age") + "\t");
            System.out.print(rs.getTimestamp("birth") + "\t");
            System.out.println();
        }

        rs.close();
        conn.close();
    }
}